// 45. 跳跃游戏 II
// AC: https://leetcode.cn/problems/jump-game-ii/submissions/611324928/

class Solution {
public:
    int jump(vector<int>& nums) {
        int m=0,end=0,step=0;
        for(int i=0;i<nums.size()-1;++i){
            if(m>=i){
                m=max(m,i+nums[i]);
                if(i==end){
                    end=m;
                    ++step;
                }
            }
        }
        return step;
    }
};